package com.app.micaihu.ad.toutiao;


import com.app.micaihu.bean.ad.NativeAd;

import java.util.HashMap;

/**
 * 广点通广告管理类
 *
 * @author linkai
 */
public class ToutiaoAdManager {

    private ToutiaoAdManager() {
        if (instance != null) {
            throw new RuntimeException("ToutiaoAdManager 已经初始化...");
        }
    }

    public static volatile ToutiaoAdManager instance;

    public static ToutiaoAdManager getInstance() {
        if (instance == null) {
            synchronized (ToutiaoAdManager.class) {
                if (instance == null) {
                    instance = new ToutiaoAdManager();
                }
            }
        }
        return instance;
    }

    //所有广告集合__百度广告集合的<adId,manaer>
    private final HashMap<String, ToutiaoNativeAd> toutiaoNativeAdManagerHashMap = new HashMap<>();
    private ToutiaoNativeAd gdtNativeAd;

    public void putAd(NativeAd nativeAd) {
        if (nativeAd == null) return;
        if (!toutiaoNativeAdManagerHashMap.containsKey(nativeAd.getAdId())) {
            gdtNativeAd = new ToutiaoNativeAd(nativeAd);
            toutiaoNativeAdManagerHashMap.put(nativeAd.getAdId(), gdtNativeAd);
        }
    }

    public ToutiaoNativeAd getAd(String id) {
        return toutiaoNativeAdManagerHashMap.get(id);
    }
}
